Basic work for cargo install
authorSteve Klabnik <steve@steveklabnik.com>
Sun, 22 Feb 2015 23:06:12 +0000 (00:06 +0100)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 19 Oct 2015 04:38:42 +0000 (21:38 -0700)
src/bin/cargo.rs
src/bin/install.rs [new file with mode: 0644]
src/cargo/ops/cargo_install.rs [new file with mode: 0644]
src/cargo/ops/mod.rs
tests/support/mod.rs

index bfa763852e021c3456e26a804f766cd75035011e..11019d1ead464f744bdb9369e05b637f4e5888c4 100644 (file)
@@ -69,6 +69,7 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
     $mac!(generate_lockfile);
     $mac!(git_checkout);
     $mac!(help);
+    $mac!(install);
     $mac!(locate_project);
     $mac!(login);
     $mac!(new);
diff --git a/src/bin/install.rs b/src/bin/install.rs
new file mode 100644 (file)
index 0000000..8f44334
--- /dev/null
@@ -0,0 +1,89 @@
+use cargo::ops;
+use cargo::util::{CliResult, CliError, Config};
+use std::path::Path;
+
+#[allow(dead_code)] // for now until all options are implemented
+
+#[derive(RustcDecodable)]
+struct Options {
+    flag_jobs: Option<u32>,
+    flag_features: Vec<String>,
+    flag_no_default_features: bool,
+    flag_debug: bool,
+    flag_bin: Option<String>,
+    flag_example: Vec<String>,
+    flag_package: Vec<String>,
+    flag_verbose: bool,
+    flag_root: Option<String>,
+}
+
+pub const USAGE: &'static str = "
+Install a crate onto the local system
+
+Installing new crates:
+    cargo install [options]
+    cargo install [options] [-p CRATE | --package CRATE] [--vers VERS]
+    cargo install [options] --git URL [--branch BRANCH | --tag TAG | --rev SHA]
+    cargo install [options] --path PATH
+
+Managing installed crates:
+    cargo install [options] --list
+
+Options:
+    -h, --help              Print this message
+    -j N, --jobs N          The number of jobs to run in parallel
+    --features FEATURES     Space-separated list of features to activate
+    --no-default-features   Do not build the `default` feature
+    --debug                 Build in debug mode instead of release mode
+    --bin NAME              Only install the binary NAME
+    --example EXAMPLE       Install the example EXAMPLE instead of binaries
+    -p, --package CRATE     Install this crate from crates.io or select the
+                            package in a repository/path to install.
+    -v, --verbose           Use verbose output
+    --root DIR              Directory to install packages into
+
+This command manages Cargo's local set of install binary crates. Only packages
+which have [[bin]] targets can be installed, and all binaries are installed into
+`$HOME/.cargo/bin` by default (or `$CARGO_HOME/bin` if you change the home
+directory).
+
+There are multiple methods of installing a new crate onto the system. The
+`cargo install` command with no arguments will install the current crate (as
+specifed by the current directory). Otherwise the `-p`, `--package`, `--git`,
+and `--path` options all specify the source from which a crate is being
+installed. The `-p` and `--package` options will download crates from crates.io.
+
+Crates from crates.io can optionally specify the version they wish to install
+via the `--vers` flags, and similarly packages from git repositories can
+optionally specify the branch, tag, or revision that should be installed. If a
+crate has multiple binaries, the `--bin` argument can selectively install only
+one of them, and if you'd rather install examples the `--example` argument can
+be used as well.
+
+The `--list` option will list all installed packages (and their versions).
+";
+
+pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+    config.shell().set_verbose(options.flag_verbose);
+
+    let compile_opts = ops::CompileOptions {
+        config: config,
+        jobs: options.flag_jobs,
+        target: None,
+        features: &options.flag_features,
+        no_default_features: options.flag_no_default_features,
+        spec: None,
+        exec_engine: None,
+        mode: ops::CompileMode::Build,
+        release: true,
+        filter: ops::CompileFilter::Everything,
+        target_rustc_args: None,
+    };
+
+    let root = &Path::new("$HOME/.cargo/bin");
+
+    ops::install(&root,
+                 &compile_opts).map_err(|err| {
+        CliError::from_boxed(err, 101)
+    }).map(|_| None)
+}
diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs
new file mode 100644 (file)
index 0000000..2bd65cc
--- /dev/null
@@ -0,0 +1,17 @@
+use ops;
+use util::CargoResult;
+use sources::PathSource;
+use std::path::Path;
+
+pub fn install(manifest_path: &Path,
+               opts: &ops::CompileOptions) -> CargoResult<()> {
+    let config = opts.config;
+    let src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
+                                            config));
+    let _root = try!(src.root_package());
+
+    println!("Compiling");
+    try!(ops::compile(manifest_path, opts));
+
+    Ok(())
+}
index f408b093aa94061c85702f313d751a861a94f23f..5aa156cd61f21006f8f64dbf51808b2aba3ce740 100644 (file)
@@ -7,6 +7,7 @@ pub use self::cargo_rustc::{Context, LayoutProxy};
 pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
 pub use self::cargo_rustc::{CommandType, CommandPrototype, ExecEngine, ProcessEngine};
 pub use self::cargo_run::run;
+pub use self::cargo_install::install;
 pub use self::cargo_new::{new, NewOptions, VersionControl};
 pub use self::cargo_doc::{doc, DocOptions};
 pub use self::cargo_generate_lockfile::{generate_lockfile};
@@ -28,6 +29,7 @@ mod cargo_compile;
 mod cargo_doc;
 mod cargo_fetch;
 mod cargo_generate_lockfile;
+mod cargo_install;
 mod cargo_new;
 mod cargo_package;
 mod cargo_pkgid;
index 38e4348705d23fb958f213456d5ce411f7f01e82..90b1dfac81f30d7c73ed230c542936c5a5dc7454 100644 (file)
@@ -563,3 +563,4 @@ pub static DOWNLOADING: &'static str = " Downloading";
 pub static UPLOADING:   &'static str = "   Uploading";
 pub static VERIFYING:   &'static str = "   Verifying";
 pub static ARCHIVING:   &'static str = "   Archiving";
+pub static INSTALLED:   &'static str = "   Installed";